package video

import (
	"hy_808/protocol/hygprs"
)

/*
新格式视频指令包
+0   a0 00 36 02 00 ae c2
+7   01 00 00 00 01
+12  02 00 00 91 31
+17  04 b5 e1 54 88
+22  06 61 ea 63 05
+27  10                    快速定位音视频
+28  01                    状态操作码
+29  00 20                 摄像头编号
+31  02                    视频传输方式:01,实时;02,回放
+32  61 e9 f7 80           开始时间
+36  61 eb 48 ff           结束时间
+40  0a 26 e8 7b eb 00     视频服务器地址
+46  00 20                 音频通道号
+48  01                    快进/慢放倍数
-5   00 00 0f 63 a1
*/
type NewerCommand struct {
	hygprs.Fields
}

func MakeNewerCommand(p hygprs.Packet) NewerCommand {
	return NewerCommand{hygprs.MakeFields(p)}
}

/*
Base1246
*/
func (p *NewerCommand) LineID() uint32 {
	return hygprs.ToUint32(p.Data[8:12])
}

func (p *NewerCommand) SetLineID(v uint32) {
	copy(p.Data[8:12], hygprs.FromUint32(v))
}

func (p *NewerCommand) BusID() uint32 {
	return hygprs.ToUint32(p.Data[13:17])
}

func (p *NewerCommand) SetBusID(v uint32) {
	copy(p.Data[13:17], hygprs.FromUint32(v))
}

func (p *NewerCommand) OperatorID() uint32 {
	return hygprs.ToUint32(p.Data[18:22])
}

func (p *NewerCommand) SetOperatorID(v uint32) {
	copy(p.Data[18:22], hygprs.FromUint32(v))
}

func (p *NewerCommand) TimeStamp() uint32 {
	return hygprs.ToUint32(p.Data[23:27])
}

func (p *NewerCommand) SetTimeStamp(v uint32) {
	copy(p.Data[23:27], hygprs.FromUint32(v))
}

/*
与旧格式通用的字段
*/
func (p *NewerCommand) ActionType() byte {
	return p.Data[27]
}

func (p *NewerCommand) SetActionType(v byte) {
	p.Data[27] = v
}

func (p *NewerCommand) StatusActionCode() byte {
	return p.Data[28]
}

func (p *NewerCommand) SetStatusActionCode(v byte) {
	p.Data[28] = v
}

func (p *NewerCommand) PassageCode() uint16 {
	return hygprs.ToUint16(p.Data[29:31])
}

//func (p *NewerCommand) SetPassageCode(v uint16) {
//	copy(p.Data[29:31], hygprs.FromUint16(v))
//}

func (p *NewerCommand) TransMode() byte {
	return p.Data[31]
}

func (p *NewerCommand) SetTransMode(v byte) {
	p.Data[31] = v
}

func (p *NewerCommand) SetTimeRange(start, end uint32) {
	copy(p.Data[32:36], hygprs.FromUint32(start))
	copy(p.Data[36:40], hygprs.FromUint32(end))
}

func (p *NewerCommand) ServerAddr() string {
	return hygprs.ToIPAddr(p.Data[40:47])
}

func (p *NewerCommand) SetServerAddr(addr string) {
	copy(p.Data[40:47], hygprs.FromIPAddr(addr))
}

/*
新格式特有的字段
*/

func (p *NewerCommand) VideoCode() uint16 {
	return hygprs.ToUint16(p.Data[29:31])
}

func (p *NewerCommand) SetVideoCode(v uint16) {
	copy(p.Data[29:31], hygprs.FromUint16(v))
}

func (p *NewerCommand) AudioCode() uint16 {
	return hygprs.ToUint16(p.Data[46:48])
}

func (p *NewerCommand) SetAudioCode(v uint16) {
	copy(p.Data[46:48], hygprs.FromUint16(v))
}

func (p *NewerCommand) PlaybackSpeed() byte {
	return p.Data[48]
}

func (p *NewerCommand) SetPassageCode(video, audio uint16) {
	p.SetVideoCode(video)
	p.SetAudioCode(audio)
}
